﻿using MJTop.BLL.SYS;
using MJTop.Web.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace MJTop.WebApp.Controllers
{
    public class LoginController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(string loginName, string password)
        {
            var retful = UserBLL.Login(loginName, password);
            if (retful.Code == 1)
            {
                Session[BaseController.CONST_SESSION_USER] = retful.Value;
                return Redirect("/Home/Index");
            }
            else
            {
                return View(retful);
            }
        }

        public ActionResult LogOut()
        {
            Session.Clear();
            Session.Abandon();
            foreach (var key in Request.Cookies.AllKeys)
            {
                if (key == BaseController.CONST_COOKIE_UNAME)
                {
                    continue;
                }
                Response.Cookies[key].Expires = DateTime.Now.AddDays(-30);
            }
            return Redirect("/Login/Index");
        }

        public ActionResult login_timeout()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ajaxlogin(string loginName, string password)
        {
            var retful = UserBLL.Login(loginName, password);
            if (retful.Code == 1)
            {
                Session[BaseController.CONST_SESSION_USER] = retful.Value;
                return this.JsonBJUI(200, "登陆成功！");
            }
            else
            {
                return this.JsonBJUI(300, retful.Msg);
            }
        }

    }
}